//
//  BaseVC.swift
//  NavTran
//
//  Created by 郑东喜 on 2017/1/7.
//  Copyright © 2017年 郑东喜. All rights reserved.
//

import UIKit

class BaseVC: UIViewController,UIGestureRecognizerDelegate {
    
    var titl = UILabel()
    
    //标题
    var tleStr : String?
    
    //左边按钮
    var leftItemBtn = UIButton()
    
    //右边按钮
    var rightItemBtn = UIButton()
    
    
    var navBar = UINavigationBar()
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        // Do any additional setup after loading the view.
        view.backgroundColor = UIColor.white
        
        //启动滑动手势
        self.navigationController?.interactivePopGestureRecognizer?.delegate = self

        navBar = UINavigationBar(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 64))
        
        navBar.barTintColor = UIColor.white
        self.view.addSubview(navBar)
        
        titl = UILabel()
        titl.frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width / 3, height: 30)
        titl.center = navBar.center
        titl.text = "asdsad"
        titl.textAlignment = .center
        navBar.addSubview(titl)
        
        //左边按钮
        leftItemBtn = UIButton()
        leftItemBtn.frame = CGRect(x: 20, y: 30, width: 25, height: 25)
        leftItemBtn.backgroundColor = UIColor.red
        leftItemBtn.addTarget(self, action: #selector(pop), for: .touchUpInside)
        leftItemBtn.isHidden = true
        
        //左边按钮
        rightItemBtn = UIButton()
        rightItemBtn.frame = CGRect(x: UIScreen.main.bounds.width - 45 , y: 30, width: 25, height: 25)
        rightItemBtn.backgroundColor = UIColor.red
        
        rightItemBtn.isHidden = true
        
        navBar.addSubview(leftItemBtn)
        navBar.addSubview(rightItemBtn)
        
        if (self.navigationController?.viewControllers.count)! >= 2 {
            leftItemBtn.isHidden = false
            rightItemBtn.isHidden = false
        }
        

    }
    
}


extension BaseVC {
     @objc fileprivate func pop() -> Void {
        self.navigationController?.popViewController(animated: true)
    }
}
